<?

$salida = new stdClass();


// get info
$un = $_POST['usernamephp'];
$pw = $_POST["passwordphp"];
$query = $_POST["queryphp"];
$query = stripslashes($query);

//connect to the db
//$conn = mssql_connect("WSSSERVER", $user, $pswd)
$conn = mssql_connect("WSSSERVER", $un, $pw)
	or die("Couldn't connect to SQL Server on WSSSERVER");
	
//select a database to work with
$selected = mssql_select_db("Punchcard", $conn)
	or die("Couldn't open database Punchcard");

//execute the SQL query and return records
$sql=mssql_query("".$query."",$conn) or die("query error: ".mssql_get_last_message());

while($row=mssql_fetch_assoc($sql))
{
	$row['comments']=utf8_encode($row['comments']);
	$salida->resultados[] = $row;
}

mssql_close($conn);

print(json_encode($salida));

?>